package myjava.lang.reflect.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ReflectionHandler implements InvocationHandler {

    private Object invoker;

    public ReflectionHandler(Object invoker){
        this.invoker = invoker;
    }

    public <T> T getProxy(){
        return (T)Proxy.newProxyInstance(this.getClass().getClassLoader(), invoker.getClass().getInterfaces() , this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(invoker, args);
    }
}
